﻿<%@ Page Language="C#" ValidateRequest="false" %>

<%@ Register Assembly="Typps" Namespace="Typps" TagPrefix="t" %>
<%--/*http://developer.yahoo.com/yui/yuitest/*/--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!--CSS-->
    <link rel="stylesheet" type="text/css" href="../yuitest/css/logger.css" />
    <link rel="stylesheet" type="text/css" href="../yuitest/css/testlogger.css" />
    <!-- Dependencies -->
    <script src="../yuitest/yahoo-dom-event.js" type="text/javascript"></script>
    <script src="../yuitest/logger-min.js" type="text/javascript"></script>
    <!-- Source File -->
    <script src="../yuitest/yuitest-min.js" type="text/javascript"></script>
    <script src="../yuitest/event-simulate-min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" ScriptMode="Debug" runat="server">
        </asp:ScriptManager>
        <t:Editor ID="Editor1" runat="server">
        </t:Editor>
    </div>
    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler)
        function pageLoadedHandler(sender, eventArgs) {
            var oTestCase = new YAHOO.tool.TestCase({

                name: "ToolBar",

                //---------------------------------------------
                // Setup and tear down
                //---------------------------------------------

                setUp: function () {
                    this.editor = $find('<%= Editor1.ClientID %>');
                },

                tearDown: function () {
                    delete this.editor;
                },

                //---------------------------------------------
                // Tests
                //---------------------------------------------
                /*test tabs and then merge into editor*/
                testToolBarCollection: function () {
                    var length = this.editor.get_toolBarCollection().length;
                    YAHOO.util.Assert.areEqual(5, length, "length should be 5");
                },

                testToolBarSet: function () {
                    var toolBars = this.editor.get_toolBars();
                    var length = toolBars.count();
                    YAHOO.util.Assert.areEqual(5, length, "length should be 5");
                },

                testToolBarDecendantsContractVerification: function () {
                    var toolBars = this.editor.get_toolBars();
                    var toolBarSets = toolBars.items;
                    for (var i in toolBarSets) {
                        var toolBarSet = toolBarSets[i];
                        var implementsIComposite = Typps.IComposite.isImplementedBy(toolBarSet);
                        YAHOO.util.Assert.areEqual(implementsIComposite, true, "All ToolBarSets must implement the IComposite contract");
                        var isToolBarSetType = Typps.ToolBarSet.isInstanceOfType(toolBarSet);
                        YAHOO.util.Assert.areEqual(isToolBarSetType, true, "All ToolBarSets must derive from ToolBarSet class");
                        var toolBarItems = toolBarSet.items;
                        for (var j in toolBarItems) {
                            var item = toolBarItems[j];
                            var implementsIButtonItem = Typps.IButtonItem.isImplementedBy(item);
                            YAHOO.util.Assert.areEqual(implementsIButtonItem, true, "All ToolBarItems must implement the IButtonItem contract");
                            var isToolBarItemType = Typps.ToolBarItem.isInstanceOfType(item);
                            YAHOO.util.Assert.areEqual(isToolBarItemType, true, "All ToolBarItems must derive from ToolBarItem class");
                        }
                    }
                },

                testToolBarSetIconsModeAddGetRemove: function () {
                    toolBarItemsTest(this.editor, { mode: 0 });
                },

                testToolBarSetImageSpritesModeAddGetRemove: function () {
                    toolBarItemsTest(this.editor, { mode: 1 });
                }
            });
            var toolBarItemsTest = function (instance, options) {
                var divider = false;
                var enabled = true;
                var icon = null;
                var marginLeft = 0;
                var index = 0;
                var title = 'hello';
                var isOptions = false;
                var leftBorderImage = '';
                var optionsName = '';
                var optionsImage = '';
                var optionsTitle = '';
                var barItemType = 0; /*Typps.BarItemType.ToolBarItem*/
                var distance = 0;
                var name1 = '';
                var name2 = '';
                var disabledBackColor = '';
                var disabledBorderColor = '';
                var disabledTransparency = '';
                var toggleEnabled = false;
                var groupName = '';
                instance.set_mode(options.mode); //Typps.Editor.IconType

                var toolBarSet = instance.createToolBarSet(leftBorderImage, optionsName, optionsImage, optionsTitle, document.createElement('div'));
                var command = new Typps.Command(null/*ToolBarItem will make itself the sender when null*/, function (sender, args) {
                    name1 = sender.get_name();
                });
                var toolBarItem = instance.createToolBarItem('item1', divider, icon, marginLeft, index, title, isOptions, enabled, barItemType, distance, toggleEnabled, groupName,
            disabledBackColor, disabledBorderColor, disabledTransparency, command, document.createElement('a'));
                toolBarSet.add(toolBarItem);

                isOptions = true; //test options item as well
                command = new Typps.Command(null/*ToolBarItem will make itself the sender when null*/, function (sender, args) {
                    name2 = sender.get_name();
                });
                var toolBarOption = instance.createToolBarItem('options1', divider, icon, marginLeft, index, title, isOptions, enabled, barItemType, distance, toggleEnabled, groupName,
            disabledBackColor, disabledBorderColor, disabledTransparency, command, document.createElement('a'));

                toolBarSet.add(toolBarOption);

                var length = 0;
                for (var i in toolBarSet.items)
                    length++;

                YAHOO.util.Assert.areEqual(2, length, "length should be exactly 1");

                var item1 = toolBarSet.item('item1');
                YAHOO.util.Assert.areEqual(toolBarItem, item1, "we were not able to retrieve the element we added?");
                YAHOO.util.UserAction.click(item1.get_element());
                YAHOO.util.Assert.areEqual('item1', name1, String.format("the name of this command must be {0}", name1));

                var option1 = toolBarSet.item('options1');
                YAHOO.util.Assert.areEqual(toolBarOption, option1, "we were not able to retrieve the option item we added?");
                YAHOO.util.UserAction.click(option1.get_element());
                YAHOO.util.Assert.areEqual('options1', name2, String.format("the name of this command must be {0}", name2));

                toolBarSet.remove('item1');
                toolBarSet.remove('options1');
                length = 0;
                for (var j in toolBarSet.items)
                    length++;

                YAHOO.util.Assert.areEqual(0, length, "length should be 0");
                //clean up
                toolBarItem.dispose();
                toolBarOption.dispose();
                toolBarSet.dispose();
            }
            //create the logger
            var logger = new YAHOO.tool.TestLogger();

            //add the test cases and suites
            YAHOO.tool.TestRunner.add(oTestCase);

            //run all tests
            YAHOO.tool.TestRunner.run();
        }
    </script>
    </form>
</body>
</html>
